//
//  HomeBannerCell.swift
//  BA_MARRY_SWIFT
//
//  Created by 王洋 on 2021/5/17.
//

import UIKit

import Kingfisher
import SDCycleScrollView

class HomeBannerCell: UITableViewCell {
    
    var itemModel:HomeADItemModel?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = UIColor.white
        
        self.addSubview(self.bannerView)
        self.bannerView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
        
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    var bannerView: SDCycleScrollView = {
        let bannerView = SDCycleScrollView()
        bannerView.autoScrollTimeInterval = 5;
        bannerView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        
        return bannerView
    }()
    
    func fillCellWithModel(model:HomeADItemModel)  {
        itemModel = model
        
        var imageURLStringsGroup:[String] = []
        
        let events:[HomeADItemEventModel] = (itemModel?.sysAdvertisement!.sysAdvEventList)!
        for eventModel in events {
            imageURLStringsGroup.append(eventModel.url ?? "")
        }
        
        bannerView.imageURLStringsGroup = imageURLStringsGroup
        
    }
    
}

extension HomeBannerCell:SDCycleScrollViewDelegate {


    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
        print(index)
    }


}
